package com.example.administrator.text;

import android.content.Intent;
import android.os.Bundle;
import com.uzmap.pkg.openapi.ExternalActivity;
import com.uzmap.pkg.openapi.Html5EventListener;
import com.uzmap.pkg.openapi.WebViewProvider;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONException;
import org.json.JSONObject;
import util.LogUtil;

/**
 *   消息
 */
public class APICloud3Activity extends ExternalActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LogUtil.eE("","APICloudActivity");
        EventBus.getDefault().register(this);
        addHtml5EventListener(new Html5EventListener("receiveMessage") {
            @Override
            public void onReceive(WebViewProvider webViewProvider, Object o) {
                LogUtil.eE("","........addHtml5EventListener.......收到apiCloud的信息....");
                Intent intent = new Intent(HomeActivity.mAction);
                intent.putExtra("wifi","jPush_context");
                intent.putExtra("jPush_context","ok");
                sendBroadcast(intent);
            }
        });

    }

    /**
     * 给apiCloud 发送消息
     */
    private void setOnClin(String context) throws JSONException {
        LogUtil.eE("",".........给apiCloud 发送消息.......pullData......");
        JSONObject extra = new JSONObject();
        extra.put("fff",context);
        sendEventToHtml5("pullData",new JSONObject(context));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        removeAllHtml5EventListener();
        EventBus.getDefault().unregister(this);
    }

    /*** 订阅事件FirstEvent*/
    @Subscribe
    public void onEventMainThread(final String string){
        try {
            setOnClin(string);
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
}
